/* eslint-disable no-restricted-syntax */
// 初始化表单数据
export function initListenerForm (listener) {
  let self = {
    ...listener
  }
  if (listener.script) {
    self = {
      ...listener,
      ...listener.script,
      scriptType: listener.script.resource ? 'externalScript' : 'inlineScript'
    }
  }
  if (listener.event === 'timeout' && listener.eventDefinitions) {
    if (listener.eventDefinitions.length) {
      let k = ''
      for (const key in listener.eventDefinitions[0]) {
        console.log(listener.eventDefinitions, key)
        if (key.indexOf('time') !== -1) {
          k = key
          self.eventDefinitionType = key.replace('time', '').toLowerCase()
        }
      }
      console.log(k)
      self.eventTimeDefinitions = listener.eventDefinitions[0][k].body
    }
  }
  return self
}

export function initListenerType (listener) {
  console.log(listener, 'listener')
  let listenerType
  let id
  if (listener.class) listenerType = 'classListener'
  if (listener.expression) listenerType = 'expressionListener'
  if (listener.delegateExpression) listenerType = 'delegateExpressionListener'
  if (listener.script) listenerType = 'scriptListener'
  if (listener.$attrs) {
    id = listener.$attrs.id || ''
  }
  return {
    ...JSON.parse(JSON.stringify(listener)),
    ...(listener.script || {}),
    listenerType,
    id
  }
}

export const listenerType = {
  classListener: 'javaClass',
  expressionListener: 'expression',
  delegateExpressionListener: 'registerExpression',
  scriptListener: 'script'
}

export const eventType = {
  create: 'create',
  assignment: 'assign',
  complete: 'accomplished',
  delete: 'delete',
  update: 'update',
  timeout: 'overtime'
}

export const fieldType = {
  string: 'string',
  expression: 'expression'
}
